<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title></title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    

<link rel="stylesheet" type="text/css" href="../css/edittable.css"  ></link>  
<link rel="stylesheet" type="text/css" href="../css/validate.css"  ></link>  
<script type="text/javascript"  src="../js/jquery-1.8.0.js"></script>

 	<script>
 			var result1 = false;
 			var result2 = false;
 			var result3 = false;
			$(function(){
				 $("input[type=text],textarea").focus(function(){
					  $(this).addClass("input_focus");
					}).blur(function(){
							$(this).removeClass("input_focus");
					});

				$(".form_btn").hover(function(){
						$(this).css("color","red").css("background","#6FB2DB");
					},
					
					function(){
						$(this).css("color","#295568").css("background","#BAD9E3");
					});	
				
				
				
				//表单校验
				
				$("#adminName").blur(function(){
					var text = /^[a-zA-Z0-9]{4,15}$/;
					var a=$("#adminName").val().toLowerCase();
					if(text.test(a)){
						$.ajax({
							url:"AdminServlet.do",
							type:"post",
							data:{adminName:a,flag:"check"},
							success:function(data){
								if(data==1){
									$("#adminName_msg").html("√");
									$("#adminName_msg").css("color","green");
									result1=true;
								}else{
									$("#adminName_msg").html("用户账号已被注册");
									$("#adminName_msg").css("color","red");
									result1=false;
								}
							}
						})
					}else{
						$("#adminName_msg").html("输入错误，4-15位，只限数字(0-9)和英文(a-z),不区分大小写");
						$("#adminName_msg").css("color","red");
						result1=false;
					}
					
				})
				
				
				$("#password").blur(function(){
					var text = /^[a-zA-Z0-9]{6,20}$/;
					var a=$("#password").val();
					if(text.test(a)){
						$("#password_msg").html("√");
						$("#password_msg").css("color","green");
						result2=true;
					}else{
						$("#password_msg").html("输入错误，数字或英文,6-20位");
						$("#password_msg").css("color","red");
						result2=false;
					}
				})
				
				$("#pwdconfirm").blur(function(){
					var a=$("#pwdconfirm").val();
					var b=$("#password").val();
					if(a==b){
						$("#pwdconfirm_msg").html("√");
						$("#pwdconfirm_msg").css("color","green");
						result3=true;
					}else{
						$("#pwdconfirm_msg").html("输入错误，两次密码不一致");
						$("#pwdconfirm_msg").css("color","red");
						result3=false;
					}
					
				})
				
			});		
	</script>
	
	
	<script>
		function validate(){
			var result=result1&result2&result3;
			if(result){
				var l = confirm("确定要提交吗");
				if(l){
					return true;
				}else{
					return false;
				}
				
			}else{
				alert("请按要求填写");
				return false;
			}
			
		}
	</script>
</head>



<body>
	<div class ="div_title">
		 <div class="div_titlename"> <img src="../images/san_jiao.gif" ><span>管理员添加</span></div>
	 </div>
				 
	 <form action="AdminServlet.do?flag=add" method="post">
		 <table class="edit_table" >
		 		<tr>
		 			 	<td class="td_info">用户账号:</td>	
		 			 	<td class="td_input_short"> 
		 			 		<input type="text" class="txtbox" id="adminName" name="adminName" value="${param.adminName}"/>
		 			 	</td>   
		 			 	<td>
		 			 		<label class="validate_info" id="adminName_msg">4-15位；只限数字(0-9)和英文(a-z),不区分大小写</label>
		 			 	</td> 
		 		</tr>
		 			<tr>
		 				<td class="td_info">用户密码:</td>	
		 				<td>
		 					<input type="text"  class="txtbox"  name="password"  id="password" value="${param.password}"/>
		 				</td> 
		 				<td><label  class="validate_info" id="password_msg" >数字或英文,6-20位</label></td>	
		 		</tr>
		 			<tr>
		 				<td class="td_info">重复密码:</td>	
		 				<td><input type="text" class="txtbox" id="pwdconfirm"  value="${param.password} "/>
		 				</td>
		 				<td><label  class="validate_info"  id="pwdconfirm_msg">请重复输入密码</label></td>	
		 		</tr>
		 		<tr>
		 			<td class="td_info">备注信息:</td>	
		 			<td><textarea rows="4" cols="27" name="note" class="txtarea" >${param.note}</textarea> </td>	
		 			<td><label></label></td>	
		 		</tr>
		 		<tr>
		 			<td class="td_info"> </td>	
		 			<td> 
		 			<input class="form_btn" type="submit" value="提交"  onclick="return validate()"/> 
		 			<input type="reset"  class="form_btn" value="重置" /> </td>	
		 			<td>
		 				<label id="result_msg" class="result_msg">${msg}</label>
		 			</td>	
		 		</tr>
		</table>
     </form>
</body>
</html>